<template>
  <view>
      <daya-clone-navbar :prop_clone_navbar="clone_navbar" :prop_is_ipx="is_ipx"/>

    <navigator
      class="return-index-btn"
      openType="redirect"
      url="/pages/index/index"
      v-if="show_index"
    >
      <image
        src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/images/nav-icon-index.png"
        style="width: 50rpx; height: 50rpx"
      ></image>
    </navigator>

    <view class="w-full flex  flex-nowrap overflow-x-scroll  bg-white border-0 border-b-1 border-gray-300 border-solid  tab-bar">
      <view class="flex-1 flex-grow-1">
        <navigator
            :class="status == -1 ? 'active' : ''"
            openType="redirect"
            url="order?status=-1"
        >
          <text
              :style="
              'color:' +
              (status == -1 ? color : '') +
              ';border-bottom:' +
              (status == -1 ? 2 : 0) +
              'rpx solid ' +
              color
            "
          >全部</text>
        </navigator>
      </view>
      <view class="flex-1 flex-grow-1">
        <navigator
          :class="status == 1 ? 'active' : ''"
          openType="redirect"
          url="order?status=1"
        >
          <text
            :style="
              'color:' +
              (status == 1 ? color : '') +
              ';border-bottom:' +
              (status == 1 ? 2 : 0) +
              'rpx solid ' +
              color
            "
            >待付款</text
          >
        </navigator>
      </view>
      <view class="flex-1 flex-grow-1">
        <navigator
          :class="status == 2 ? 'active' : ''"
          openType="redirect"
          url="order?status=2"
        >
          <text
            :style="
              'color:' +
              (status == 2 ? color : '') +
              ';border-bottom:' +
              (status == 2 ? 2 : 0) +
              'rpx solid ' +
              color
            "
            >待发货</text
          >
        </navigator>
      </view>
      <view class="flex-1 flex-grow-1">
        <navigator
          :class="status == 3 ? 'active' : ''"
          openType="redirect"
          url="order?status=3"
        >
          <text
            :style="
              'color:' +
              (status == 3 ? color : '') +
              ';border-bottom:' +
              (status == 3 ? 2 : 0) +
              'rpx solid ' +
              color
            "
            >待收货</text
          >
        </navigator>
      </view>
      <view class="flex-1 flex-grow-1">
        <navigator
          :class="status == 4 ? 'active' : ''"
          openType="redirect"
          url="order?status=4"
        >
          <text
            :style="
              'color:' +
              (status == 4 ? color : '') +
              ';border-bottom:' +
              (status == 4 ? 2 : 0) +
              'rpx solid ' +
              color
            "
            >已完成</text
          >
        </navigator>
      </view>
      <view class="flex-1 flex-grow-1">
        <navigator
          :class="status == 5 ? 'active' : ''"
          openType="redirect"
          url="order?status=5"
        >
          <text
            :style="
              'color:' +
              (status == 5 ? color : '') +
              ';border-bottom:' +
              (status == 5 ? 2 : 0) +
              'rpx solid ' +
              color
            "
            >售后</text
          >
        </navigator>
      </view>
    </view>
    <view class="order-list">
      <view
        class="join"
        style="margin-bottom: 20rpx"
        v-if="status == 1 && dfkts"
      >
        <image
          class="jion-img"
          src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/laba.png"
          :style="'background:' + color"
        ></image>
        <view class="jionbo ctwz" style="color: #666; border: none"
          >待付款订单2小时后自动取消，请尽快支付！</view
        >
        <image
          @tap="closets"
          class="jion-jtimg"
          src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/close.png"
        ></image>
      </view>
      <view class="no-data-tip zwdd" v-if="order_list.length == 0 && mygd">
        <image
          mode="aspectFit"
          src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/list.png"
        ></image>
        <view>您暂无相关订单哦~</view>
      </view>
      <view
        class="order-item"
        v-for="(oitem, index) in order_list"
        :key="index"
      >
        <!--<navigator openType="navigate" :url="'ddxq?oid=' + oitem.order.id">-->
        <view @click="goToPageUrl('/ymq_canyino2o/pages/wddd/ddxq?oid='+ oitem.order.id)">
          <view class="flex-row order-info">
            <view class="flex-1 flex-grow-1">订单号:{{ oitem.order.order_num }}</view>
            <view
              class="flex-grow-0"
              style="
                border: 1px solid #ccc;
                padding: 4rpx 10rpx;
                border-radius: 40rpx;
              "
              v-if="oitem.order.type == '1' && oitem.order.order_type == '1'"
              >{{ System.wm_name }}订单</view
            >
            <view
              class="flex-grow-0"
              style="
                border: 1px solid #ccc;
                padding: 4rpx 10rpx;
                border-radius: 40rpx;
              "
              v-if="oitem.order.type == '1' && oitem.order.order_type == '2'"
              >到店用餐</view
            >
            <view
              class="flex-grow-0"
              style="
                border: 1px solid #ccc;
                padding: 4rpx 10rpx;
                border-radius: 40rpx;
              "
              v-if="oitem.order.type == '2'"
              >{{ System.dc_name }}订单</view
            >
            <view class="flex-grow-0" v-if="oitem.order.type == '4'"
              >收银订单</view
            >
          </view>
          <view class="flex-row zysp flex-y-center">
            <image :src="oitem.order.logo"></image>
            <view class="flex-1 flex-grow-1 flex-col">
              <view class="mdname">
                {{ oitem.order.store_name }}
              </view>
              <view class="mdtime">
                {{ oitem.order.time }}
              </view>
            </view>
            <view class="flex-grow-0">
              <image
                src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/blackjt.png"
                style="width: 40rpx; height: 40rpx"
              ></image>
            </view>
          </view>
          <view class="goods-list">
            <view class="goods-item flex-row">
              <view
                class="flex-grow-0 flex-row flex-y-center"
                style="overflow: visible"
              >
                <image class="goods-pic" mode="aspectFill" src=""></image>
              </view>
              <view class="flex-1 flex-grow-1 flex-col">
                <view class="flex-1 flex-grow-1 flex-row flex-y-center">
                  <view class="flex-1 flex-grow-1" v-if="oitem.order.type == '4'">
                    {{
                      oitem.order.pay_type == '1'
                        ? '微信支付'
                        : oitem.order.pay_type == '2'
                        ? '余额支付'
                        : ''
                    }}
                  </view>
                  <view class="flex-1 flex-grow-1" v-else>
                    <view v-if="oitem.good.length>0">
                      {{ oitem.good[0].name }}
                    </view>
                    <text style="margin-left: 10rpx" v-if="oitem.num > 1">
                      等{{ oitem.num }}件商品
                    </text>
                  </view>
                  <view class="flex-grow-0 sfmoney">
                    ￥{{ oitem.order.money }}
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>

        <view class="flex-row" v-if="oitem.order.type != '4'">
          <view class="flex-1 flex-grow-1 flex-y-center flex-row dbbtn">
            <block v-if="status == 5">
              <view class="ddbtn" v-if="oitem.order.state == 6">已取消</view>
              <view class="ddbtn" v-if="oitem.order.dn_state == 3"
                >订单已关闭</view
              >
              <view class="ddbtn" v-if="oitem.order.state == 7"
                >已拒绝接单</view
              >
              <view class="ddbtn" v-if="oitem.order.state == 8">等待退款</view>
              <view class="ddbtn ddbtn4" v-if="oitem.order.state == 9"
                >已同意并退款</view
              >
              <view class="ddbtn ddbtn2" v-if="oitem.order.state == 10"
                >已拒绝退款</view
              >
            </block>
            <block v-else>
              <view
                class=""
                v-if="oitem.order.state == 1 || oitem.order.dn_state == 1"
              >
                <!--@tap="orderPay"-->
                <button
                  @tap="dayaOrderPay"
                  class="ddbtn ddbtn1"
                  :data-id="oitem.order.id"
                  :data-money="oitem.order.money"
                  :data-type="oitem.order.pay_type"
                  :style="
                    'border:1rpx solid ' + color + ';color:' + color + ';'
                  "
                >
                  付款
                </button>
              </view>
              <view class="" v-if="oitem.order.dn_state == 1">
                <navigator
                  openType="reLaunch"
                  :url="
                    '../smdc/smdcindex?store_id=' +
                    oitem.order.store_id +
                    '&tableid=' +
                    oitem.order.table_id +
                    '&oid=' +
                    oitem.order.id
                  "
                >
                  <button
                    class="ddbtn ddbtn1"
                    :style="
                      'border:1rpx solid ' + color + ';color:' + color + ';'
                    "
                  >
                    加菜
                  </button>
                </navigator>
              </view>
              <view class="" v-if="oitem.order.state == 2">
                <button
                  @tap="txsj"
                  class="ddbtn"
                  :data-tel="oitem.order.store_tel"
                >
                  提醒商家
                </button>
              </view>
              <view
                class=""
                v-if="oitem.order.state == 2 || oitem.order.state == 3"
              >
                <button
                  @tap="sqtk"
                  class="ddbtn"
                  :data-id="oitem.order.id"
                  :style="
                    'color:' + color + ';border: 1rpx solid ' + color + ';'
                  "
                  v-if="
                    oitem.order.pay_type == '1' || oitem.order.pay_type == '2'
                  "
                >
                  申请退款
                </button>
              </view>
              <view
                class=""
                v-if="oitem.order.state == 3 && oitem.order.order_type == '1'"
              >
                <button @tap="qrsh" class="ddbtn" :data-id="oitem.order.id">
                  确认收货
                </button>
              </view>
              <view
                class=""
                v-if="oitem.order.state == 3 && oitem.order.order_type == '2'"
              >
                <button
                  @tap="hxqh"
                  class="ddbtn"
                  :data-oid="oitem.order.oid"
                  :data-id="oitem.order.id"
                  :data-sjid="oitem.order.store_id"
                >
                  核销取货
                </button>
              </view>
              <view class="" v-if="oitem.order.state == 4">
                <navigator
                  class="ddbtn"
                  :data-id="oitem.order.id"
                  :style="
                    'background-color:' + color + ';color:#fff;border:none'
                  "
                  :url="'pjdd?oid=' + oitem.order.id"
                >
                  评价
                </navigator>
              </view>
              <view
                class=""
                v-if="oitem.order.state == 1 || oitem.order.dn_state == 1"
              >
                <button @tap="canceldd" class="ddbtn" :data-id="oitem.order.id">
                  取消
                </button>
              </view>
            </block>
            <view
              class=""
              v-if="
                oitem.order.state == 5 ||
                oitem.order.state == 6 ||
                oitem.order.state == 7 ||
                oitem.order.state == 9 ||
                oitem.order.state == 10 ||
                oitem.order.dn_state == 3
              "
            >
              <button
                @tap="orderRevoke"
                class="ddbtn ddbtn3"
                :data-id="oitem.order.id"
              >
                删除
              </button>
            </view>
          </view>
        </view>
      </view>
      <view class="jzz" v-if="!mygd">
        <image class="Rotation" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/jzz.png"></image>
        <view>加载中...</view>
      </view>
      <view class="jzwb" v-if="mygd">
        <view class="hx"></view>
        <view class="wz">加载完毕</view>
        <view class="hx"></view>
      </view>
      <view class="copyright">
        <navigator
          :appId="System.tz_appid"
          class="copyright_logo"
          extraData=""
          openType="navigate"
          path=""
          target="miniProgram"
          version="release"
        >
          <image
            class="copyright_img"
            mode="aspectFill"
            :src="System.bq_logo"
          ></image>
          <view class="copyright_text">{{ System.bq_name }}</view>
        </navigator>
        <view class="copyright_txt">{{ System.support }}</view>
      </view>
    </view>
    <view
      @tap="hideFun"
      :class="'flex-row flex-y-center modal1 ' + (hide == 1 ? 'hide' : '')"
    >
      <view
        class="flex-y-center"
        style="width: 100%; height: 800rpx; padding: 125rpx"
      >
        <view
          style="
            background-color: #fff;
            width: 100%;
            height: 100%;
            border-radius: 10rpx;
            padding: 0 50rpx;
          "
        >
          <!--<view-->
          <!--  class="flex-x-center"-->
          <!--  style="width: 100%; height: 50rpx; margin: 20rpx 0; font-size: 13pt"-->
          <!--  >核销二维码</view>-->
          <!--<image-->
          <!--  :src="'data:image/png;base64,' + hx_code"-->
          <!--  style="width: 400rpx; height: 400rpx"-->
          <!--&gt;</image>-->
          <view
            class="flex-x-center"
            style="width: 100%; height: 50rpx; margin: 20rpx 0; font-size: 14pt;text-align: center"
            >核销码</view>
          <view style="font-size: 28pt;text-align: center; margin-top: 10px;margin-bottom: 10px;">#{{hx_oid}}</view>
          <view style="font-size: 28pt;text-align: center; margin-top: 10px;margin-bottom: 10px;">{{hx_code}}</view>
          <view
            class="flex-x-center"
            style="width: 100%; height: 50rpx; font-size: 9pt"
            >出示给商家兑码核销</view>
        </view>
      </view>
    </view>


    <daya-pay
        v-if="show_pay_box"
        :type="pay_order_type"
        :order_id="pay_order_id"
        :mp_openid="wx_openid"
        :show_pay_box="show_pay_box"
        :kqyue="kqyue"
        jf_proportion=""
        :totalPrice="totalMoney"
        :user_wallet="userInfo_wallet"
        :hdfk="false"
        @close_pay_box="show_pay_box=false"
        @pay_success="pay_success"
        @pay_error="pay_error"
    ></daya-pay>

  </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index'
import gettel from '@/ymq_canyino2o/dist/gettel/index'
import util from "@/ymq_canyino2o/utils/util";
var app = getApp()
export default {
  components: {
    cardlist,
    gettel
  },
  data() {
    return {
      sssss:0,
      pay_order_type: 0,//订单类型 不传递=外卖订单  2=充值订单 3=会员订单 95=跑腿订单
      pay_order_id: 0,//跑腿订单id
      show_pay_box: false, //显示支付盒子
      wx_openid: '',
      totalMoney: 0,
      userInfo_wallet:0,
      kqyue:false, //余额支付只有在线下单时候可以实时判断
      //-------------------------------


      color: '#34aaff',
      status: -1,
      order_list: [],
      show_no_data_tip: false,
      hide: 1,
      qrcode: '',
      pagenum: 1,
      storelist: [],
      mygd: false,
      jzgd: true,
      dfkts: false,

      System: {
        wm_name: '',
        dc_name: '',
        tz_appid: '',
        bq_logo: '',
        bq_name: '',
        support: ''
      },

      hx_oid: '',
      hx_code: '',


      show_index: 0,

      oitem: {
        order: {
          id: '',
          order_num: '',
          type: '',
          order_type: '',
          logo: '',
          store_name: '',
          time: '',
          pay_type: '',
          money: '',
          state: 0,
          dn_state: 0,
          store_id: '',
          table_id: '',
          store_tel: ''
        },

        num: 0
      }
    }
  },
  onLoad: function (t) {
    this.checkLogin()
    app.globalData.setNavigationBarColor(this)
    var that = this
    console.log(getApp().globalData.xtxx1)
    if (getApp().globalData.xtxx1) {
      app.globalData.appPageOnLoad(that)
    }
    app.globalData.util.request({
      url: 'entry/wxapp/System',
      cachetime: '0',
      success: function (t) {
        console.log(t)
        var e = t.data
        if ('2' == e.model) {
          getApp().globalData.sjid = e.default_store
        }
        if ('4' == e.model) {
          getApp().globalData.sjid = e.default_store
        }
        if (null == getApp().globalData.xtxx1) {
          getApp().globalData.xtxx1 = e
          app.globalData.appPageOnLoad(that)
        }
        if ('' == t.data.dc_name) {
          t.data.dc_name = '店内'
        }
        if ('' == t.data.wm_name) {
          t.data.wm_name = '外卖'
        }
        that.setData({
          System: t.data
        })
      }
    })
    console.log(t)
    this.setData({
      status: t.status
    })
    this.reLoad()
  },
  //下拉刷新 this.reLoad()
  onPullDownRefresh() {
    this.reLoad()
    setTimeout(()=>{
      uni.stopPullDownRefresh()
    },1000);
  },
  onReachBottom: function () {
    console.log('上拉加载', this.pagenum)
    if (!this.mygd && this.jzgd) {
      this.setData({
        jzgd: false
      })
      this.reLoad()
    }
  },
  methods: {
    closets: function (t) {
      this.setData({
        dfkts: false
      })
    },

    hideFun: function (t) {
      this.setData({
        hide: 1
      })
    },

    hxqh: function (t) {
      var that = this
      var a = t.currentTarget.dataset.id
      this.hx_oid = t.currentTarget.dataset.oid
      var o = t.currentTarget.dataset.sjid
      console.log(a, o)
      uni.showLoading({
        title: '加载中',
        mask: true
      })
      app.globalData.util.request({
        // url: 'entry/wxapp/ZtCode',
        url: 'entry/wxapp/zt_code',
        cachetime: '0',
        data: {
          store_id: o,
          order_id: a
        },
        success: function (t) {
          console.log(t.data)
          that.setData({
            hx_code: t.data,
            hide: 2
          })
        }
      })
    },

    reLoad: function () {
      var t
      var that = this
      var e = this.status || -1
      var o = uni.getStorageSync('users').id
      var n = this.pagenum
      if (-1 == e) {
        t = '-1'
      }
      if (1 == e) {
        t = '1'
      }
      if (2 == e) {
        t = ''
      }
      if (3 == e) {
        t = ''
      }
      if ('4' == e) {
        e = '4,5'
        t = '2'
      }
      if ('5' == e) {
        e = '6,7,8,9,10'
        t = '3'
      }
      console.log(e, t, o, n)
      app.globalData.util.request({
        url: 'entry/wxapp/MyOrder',
        cachetime: '0',
        data: {
          dn_state: t,
          state: e,
          user_id: o,
          page: n,
          pagesize: 10
        },
        success: function (t) {
          console.log('分页返回的列表数据', t.data)
          if (t.data.length < 10) {
            that.setData({
              mygd: true,
              jzgd: true
            })
          } else {
            that.setData({
              jzgd: true,
              pagenum: that.pagenum + 1
            })
          }
          var e = that.storelist
          e = (function (t) {
            for (var e = [], a = 0; a < t.length; a++) {
              if (-1 == e.indexOf(t[a])) {
                e.push(t[a])
              }
            }
            return e
          })((e = e.concat(t.data)))
          that.setData({
            order_list: e,
            storelist: e
          })
          console.log(e)
        }
      })
    },
    dayaOrderPay(t) {
      var e = getApp().globalData.getOpenId
      var a = uni.getStorageSync('users').id
      var o = t.currentTarget.dataset.id
      var n = t.currentTarget.dataset.money
      var s = t.currentTarget.dataset.type
      console.log(e, a, o, n, s)
      if ('5' == s) {
        uni.showModal({
          title: '提示',
          content: '您的支付方式为餐后支付，请到收银台付款'
        })
        return;
      }

      //使用后端接口查询当前订单,是否能支持余额支付
      var user_id = uni.getStorageSync('users').id
      app.globalData.util.request({
        url: 'entry/wxapp/pay_is_support_amount',
        cachetime: '0',
        data: {
          user_id: user_id,
          type:s,
          order_id:o
        },
        success: (res)=> {
          console.log("res",res.data.data)
          this.kqyue=res.data.data.is_yuepay
          this.userInfo_wallet=res.data.data.wallet


          this.pay_order_type=0;//订单类型 不传递=外卖订单  2=充值订单 3=会员订单 95=跑腿订单
          this.pay_order_id=o;//跑腿订单id
          this.wx_openid=''; //传递为空,自动获取
          this.totalMoney=n;
          this.show_pay_box=true; //显示支付盒子
        }
      })


    },

    pay_success() {
      console.log("pay_success 触发")
      uni.showToast({
        title: '支付成功',
        icon: 'loading',
        duration: 1000
      })

      if (1 == this.sssss) {
        setTimeout(function () {
          uni.redirectTo({
            url: 'order?status=2'
          })
        }, 1000)
      }else if (2 == this.sssss) {
        setTimeout(function () {
          uni.redirectTo({
            url: 'order?status=4'
          })
        }, 1000)
      }else{
        this.reLoad()
      }

    },
    pay_error() {
      uni.showToast({
        title: '取消支付',
        icon: 'loading',
        duration: 1000
      })
    },

    orderPay: function (t) {
      var e = getApp().globalData.getOpenId
      var a = uni.getStorageSync('users').id
      var o = t.currentTarget.dataset.id
      var n = t.currentTarget.dataset.money
      var s = t.currentTarget.dataset.type
      this.sssss = t.currentTarget.dataset.type;
      console.log(e, a, o, n, s)
      if ('5' == s) {
        uni.showModal({
          title: '提示',
          content: '您的支付方式为餐后支付，请到收银台付款'
        })
      } else {
        uni.showLoading({
          title: '正在提交',
          mask: true
        })
        app.globalData.util.request({
          url: 'entry/wxapp/pay',
          cachetime: '0',
          data: {
            openid: e,
            money: n,
            order_id: o
          },
          success: function (t) {
            console.log(t)
            if ('0' == t.data.code) {
              uni.showModal({
                title: '提示',
                content: t.data.msg
              })
              return void setTimeout(function () {
                uni.redirectTo({
                  url: 'order?status=1'
                })
              }, 1000)
            }
            uni.hideLoading()
            uni.requestPayment({
              timeStamp: t.data.timeStamp,
              nonceStr: t.data.nonceStr,
              package: t.data.package,
              signType: t.data.signType,
              paySign: t.data.paySign,
              success: function (t) {
                console.log(t.data)
              },
              complete: function (t) {
                console.log(t)
                if ('requestPayment:fail cancel' == t.errMsg) {
                  uni.showToast({
                    title: '取消支付',
                    icon: 'loading',
                    duration: 1000
                  })
                }
                if ('requestPayment:ok' == t.errMsg) {
                  uni.showToast({
                    title: '支付成功',
                    duration: 1000
                  })
                  if (1 == s) {
                    setTimeout(function () {
                      uni.redirectTo({
                        url: 'order?status=2'
                      })
                    }, 1000)
                  }
                  if (2 == s) {
                    setTimeout(function () {
                      uni.redirectTo({
                        url: 'order?status=4'
                      })
                    }, 1000)
                  }
                }
              }
            })
          }
        })
      }
    },

    canceldd: function (t) {
      var e = t.currentTarget.dataset.id
      console.log(e)
      uni.showModal({
        title: '提示',
        content: '是否取消该订单？',
        cancelText: '否',
        confirmText: '是',
        success: function (t) {
          if (t.cancel) {
            return true
          }
          if (t.confirm) {
            uni.showLoading({
              title: '操作中'
            })
            app.globalData.util.request({
              url: 'entry/wxapp/CancelOrder',
              cachetime: '0',
              data: {
                order_id: e
              },
              success: function (t) {
                console.log(t.data)
                if ('1' == t.data) {
                  uni.showToast({
                    title: '取消成功',
                    icon: 'success',
                    duration: 1000
                  })
                  setTimeout(function () {
                    uni.redirectTo({
                      url: 'order?status=5'
                    })
                  }, 1000)
                } else {
                  uni.showToast({
                    title: '请重试',
                    icon: 'loading',
                    duration: 1000
                  })
                }
              }
            })
          }
        }
      })
    },

    orderRevoke: function (t) {
      var e = t.currentTarget.dataset.id
      console.log(e)
      uni.showModal({
        title: '提示',
        content: '是否删除该订单？',
        cancelText: '否',
        confirmText: '是',
        success: function (t) {
          if (t.cancel) {
            return true
          }
          if (t.confirm) {
            uni.showLoading({
              title: '操作中'
            })
            app.globalData.util.request({
              url: 'entry/wxapp/DelOrder',
              cachetime: '0',
              data: {
                order_id: e
              },
              success: function (t) {
                console.log(t.data)
                if ('1' == t.data) {
                  uni.showToast({
                    title: '删除成功',
                    icon: 'success',
                    duration: 1000
                  })
                  setTimeout(function () {
                    uni.redirectTo({
                      url: 'order?status=4'
                    })
                  }, 1000)
                } else {
                  uni.showToast({
                    title: '请重试',
                    icon: 'loading',
                    duration: 1000
                  })
                }
              }
            })
          }
        }
      })
    },

    txsj: function (t) {
      console.log('提醒商家' + t.currentTarget.dataset.tel)
      uni.makePhoneCall({
        phoneNumber: t.currentTarget.dataset.tel
      })
    },

    sqtk: function (e) {
      app.globalData.util.requestSM('refund').then(function (t) {
        console.log('申请退款' + e.currentTarget.dataset.id)
        uni.showModal({
          title: '提示',
          content: '申请退款么',
          success: function (t) {
            if (t.cancel) {
              return true
            }
            if (t.confirm) {
              uni.showLoading({
                title: '操作中'
              })
              app.globalData.util.request({
                url: 'entry/wxapp/TkOrder',
                cachetime: '0',
                data: {
                  order_id: e.currentTarget.dataset.id
                },
                success: function (t) {
                  console.log(t.data)
                  if ('1' == t.data) {
                    uni.showToast({
                      title: '申请成功',
                      icon: 'success',
                      duration: 1000
                    })
                    setTimeout(function () {
                      uni.redirectTo({
                        url: 'order?status=5'
                      })
                    }, 1000)
                  } else {
                    uni.showToast({
                      title: '请重试',
                      icon: 'loading',
                      duration: 1000
                    })
                  }
                }
              })
            }
          }
        })
      })
    },

    qrsh: function (t) {
      var e = t.currentTarget.dataset.id
      console.log(e)
      uni.showModal({
        title: '提示',
        content: '是否确认已收到货？',
        cancelText: '否',
        confirmText: '是',
        success: function (t) {
          if (t.cancel) {
            return true
          }
          if (t.confirm) {
            uni.showLoading({
              title: '操作中'
            })
            app.globalData.util.request({
              url: 'entry/wxapp/OkOrder',
              cachetime: '0',
              data: {
                order_id: e
              },
              success: function (t) {
                console.log(t.data)
                if ('1' == t.data) {
                  uni.showToast({
                    title: '收货成功',
                    icon: 'success',
                    duration: 1000
                  })
                  setTimeout(function () {
                    uni.redirectTo({
                      url: 'order?status=4'
                    })
                  }, 1000)
                } else {
                  uni.showToast({
                    title: '请重试',
                    icon: 'loading',
                    duration: 1000
                  })
                }
              }
            })
          }
        }
      })
    },

    orderQrcode: function (a) {
      var that = this
      var n = that.order_list
      var s = a.target.dataset.index
      uni.showLoading({
        title: '正在加载',
        mask: true
      })
      if (that.order_list[s].offline_qrcode) {
        that.setData({
          hide: 0,
          qrcode: that.order_list[s].offline_qrcode
        })
        uni.hideLoading()
      } else {
        e.request({
          url: t.order.get_qrcode,
          data: {
            order_no: n[s].order_no
          },
          success: function (t) {
            if (0 == t.code) {
              that.setData({
                hide: 0,
                qrcode: t.data.url
              })
            } else {
              uni.showModal({
                title: '提示',
                content: t.msg
              })
            }
          },
          complete: function () {
            uni.hideLoading()
          }
        })
      }
    }
  }
}
</script>
<style>
@import './order.css';
</style>
